package com.example.qxfw.hbqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.SatelliteNephoram3;
import com.example.qxfw.common.entity.zy.AirPollution;
import com.example.qxfw.common.entity.zy.EnviroStation;
import com.example.qxfw.common.entity.zy.SumAtmosphericDayData;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.hbqx.service.HjjcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


import java.util.Date;
import java.util.List;

@ApiIgnore
@Api(tags = "环保气象-环境监测")
@RestController
@CrossOrigin
@RequestMapping("/hjjc")
public class HjjcController {
    @Autowired
    private HjjcService hjjcService;


    @ApiOperation("根据观测时间段获取空气质量日统计表信息")
    @GetMapping(value = "/selectOrderByObservtimePeriodOfSumAtmosphericDayData")
    public SysResult selectOrderByObservtimePeriodOfSumAtmosphericDayData(String timeStart, String timeEnd) {
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeStart));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeEnd));
        List<SumAtmosphericDayData> sumAtmosphericDayData = hjjcService.selectOrderByObservtimePeriodOfSumAtmosphericDayData(observtimeStart, observtimeEnd);
        return SysResult.success(sumAtmosphericDayData);
    }

    @ApiOperation("根据时间段查询空气逐小时实况")
    @GetMapping(value = "/selectByTimePeriodAirPollution")
    public SysResult selectByTimePeriodAirPollution(String observtimeStart, String observtimeEnd) {
        Date dateStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeStart));
        Date dateEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeEnd));
        List<AirPollution> airPollutions = hjjcService.selectByTimePeriodAirPollution(dateStart, dateEnd);
        return SysResult.success(airPollutions);

    }

    @ApiOperation("根据开始时间查询空气逐小时实况")
    @GetMapping(value = "/selectByTimeOfAirPollution")
    public SysResult selectByTimeOfAirPollution(String observtimeStart) {
        Date dateStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeStart));
        List<AirPollution> airPollutions = hjjcService.selectByTimeOfAirPollution(dateStart);
        return SysResult.success(airPollutions);
    }

    @ApiOperation("根据时间段和站点id查询空气质量日统计表")
    @GetMapping(value = "/selectByObservtimeAndstationid")
    public SysResult selectByObservtimeAndstationid(String observtimeStart, String observtimeEnd, String stationid) {
        Date dateStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeStart));
        Date dateEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeEnd));
        List<SumAtmosphericDayData> sumAtmosphericDayData = hjjcService.selectByObservtimeAndstationid(dateStart, dateEnd, stationid);
        return SysResult.success(sumAtmosphericDayData);
    }

    @ApiOperation("根据开始时间查询空气质量日统计表")
    @GetMapping(value = "/selectByTimeOfSumAtmosphericDayData")
    public SysResult selectByTimeOfSumAtmosphericDayData(String observtimeStart) {
        Date dateStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeStart));
        List<SumAtmosphericDayData> sumAtmosphericDayData = hjjcService.selectByTimeOfSumAtmosphericDayData(dateStart);
        return SysResult.success(sumAtmosphericDayData);
    }

    @ApiOperation("降序查询所有观测时间，并只显示一条")
    @GetMapping(value = "/selectByObservtime")
    public SysResult selectByObservtime() {
        List<AirPollution> airPollutions = hjjcService.selectByObservtime();
        return SysResult.success(airPollutions);
    }

    @ApiOperation("通过城市获取环境监测站点信息")
    @GetMapping("/selectByCity")
    public SysResult selectByCity(String city) {
        List<EnviroStation> enviroStations = hjjcService.selectByCity(city);
        return SysResult.success(enviroStations);
    }

    @ApiOperation("通过城市获取环境监测站点名字")
    @GetMapping("/selectByCity1")
    public SysResult selectByCity1(String city) {
        List<EnviroStation> enviroStations = hjjcService.selectByCity1(city);
        return SysResult.success(enviroStations);
    }

    @ApiOperation("AirPollution表中降序获取除了不为StationID的最近3个不重复的observTime时间字段")
    @GetMapping("/selectByNotStationid")
    public SysResult selectByNotStationid(String stationid) {
        List<AirPollution> airPollutions = hjjcService.selectByNotStationid(stationid);
        return SysResult.success(airPollutions);
    }

    @ApiOperation("AirPollution表中获取在规定时间段中非stationid的观测时间")
    @GetMapping("/selectByObservtimeAndNotStationid")
    public SysResult selectByObservtimeAndNotStationid(String observtimeStart, String observtimeEnd, String stationid) {
        Date dateStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeStart));
        Date dateEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeEnd));
        List<AirPollution> airPollutions = hjjcService.selectByObservtimeAndNotStationid(dateStart, dateEnd, stationid);
        return SysResult.success(airPollutions);
    }

    @ApiOperation("SumAtmosphericDayData表中获取除了stationid以外的站点的观测时间")
    @GetMapping("/getObservtimeByNotStationId")
    public SysResult getObservtimeByNotStationId(String stationid) {
        List<SumAtmosphericDayData> observtime = hjjcService.getObservtimeByNotStationId(stationid);
        return SysResult.success(observtime);
    }

    @ApiOperation("SumAtmosphericDayData表获取在规定时间段中非stationid的观测时间")
    @GetMapping("/getByObservtimeAndNotStationid")
    public SysResult getByObservtimeAndNotStationid(String observtimeStart, String observtimeEnd, String stationid) {
        Date dateStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeStart));
        Date dateEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(observtimeEnd));
        List<SumAtmosphericDayData> list = hjjcService.getByObservtimeAndNotStationid(dateStart, dateEnd, stationid);
        return SysResult.success(list);
    }

    @ApiOperation("获取所有空气质量日统计表信息")
    @GetMapping("/getAllOfSumAtmosphericDayData")
    public SysResult getAllOfSumAtmosphericDayData() {
        List<SumAtmosphericDayData> list = hjjcService.getAllOfSumAtmosphericDayData();
        return SysResult.success(list);
    }

    @ApiOperation("根据元素和时间段获取空气质量日统计表信息")
    @GetMapping("/getByTimePeriodAndElementOfSumAtmosphericDayData")
    public SysResult getByTimePeriodAndElementOfSumAtmosphericDayData(String timeStart, String timeEnd, String element) {
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeStart));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeEnd));
        List<SumAtmosphericDayData> list = hjjcService.getByTimePeriodAndElementOfSumAtmosphericDayData(observtimeStart, observtimeEnd, element);
        return SysResult.success(list);
    }

    @ApiOperation("根据元素和时间点获取空气质量日统计表信息")
    @GetMapping("/getByTimeAndElementOfSumAtmosphericDayData")
    public SysResult getByTimeAndElementOfSumAtmosphericDayData(String time, String element) {
        Date observtime = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(time));
        List<SumAtmosphericDayData> list = hjjcService.getByTimeAndElementOfSumAtmosphericDayData(observtime, element);
        return SysResult.success(list);
    }

    @ApiOperation("根据元素和时间段获取空气逐小时实况")
    @GetMapping("/getByTimePeriodAndElementOfAirPollution")
    public SysResult getByTimePeriodAndElementOfAirPollution(String timeStart, String timeEnd, String element) {
        Date observtimeStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeStart));
        Date observtimeEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeEnd));
        List<AirPollution> list = hjjcService.getByTimePeriodAndElementOfAirPollution(observtimeStart, observtimeEnd, element);
        return SysResult.success(list);
    }

    @ApiOperation("根据元素和时间点获取空气逐小时实况")
    @GetMapping("/getByTimeAndElementOfAirPollution")
    public SysResult getByTimeAndElementOfAirPollution(String time, String element) {
        Date observtime = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(time));
        List<AirPollution> list = hjjcService.getByTimeAndElementOfAirPollution(observtime, element);
        return SysResult.success(list);
    }

    @ApiOperation("根据时间段查询风云3号卫星云图")
    @GetMapping("/selectByTimePeriodOfSatelliteNephoram3")
    public SysResult selectByTimePeriodOfSatelliteNephoram3(String timeStart, String timeEnd) {
        Date datecharStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeStart));
        Date datecharEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(timeEnd));
        List<SatelliteNephoram3> list = hjjcService.selectByTimePeriodOfSatelliteNephoram3(datecharStart, datecharEnd);
        return SysResult.success(list);
    }


}
